# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-xtmpl
pkgver=0.19.0
pkgrel=0
_pkgreal=xtmpl
pkgdesc="XML templating library"
url="https://framagit.org/zoggy/xtmpl"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-3.0-only"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-iri-dev
	ocaml-ppxlib-dev
	ocaml-re-dev
	ocaml-sedlex-dev
	ocaml-uutf-dev
	"
makedepends="
	$depends_dev
	dune
	ocaml
	"
subpackages="$pkgname-dev"
source="https://framagit.org/zoggy/xtmpl/-/archive/$pkgver/xtmpl-$pkgver.tar.gz"
builddir="$srcdir/$_pkgreal-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --verbose \
		-p xtmpl,xtmpl_ppx
}

check() {
	dune runtest --build-dir=.testenv --verbose \
		-p xtmpl,xtmpl_ppx
}

package() {
	dune install --destdir="$pkgdir" --docdir=/.omit \
		xtmpl xtmpl_ppx
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
d0ab7fe67f2534a5c91d9c7e55efbcbcb4fa9269cfa2016e5793efbfe76abe33d3dac28eb44cfb940f121d167b88b14a0d3ba042bbd53a5d4dd379c27fae2328  xtmpl-0.19.0.tar.gz
"
